<!-- good使用 -->
<template>
  <div class="cartcontrol">
    <div class="cart-dec icon-remove_circle_outline" v-show="foodCount > 0" @click.stop="decCart"></div>
    <div class="cart-count" v-show="foodCount > 0 ">{{ foodCount }}</div>
    <div class="cart-add icon-add_circle" @click.stop="addCart"></div>
  </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: 'cartcontrol',
  props: {
    food: {
      type: Object
    }
  },
  data () {
    return {}
  },
  methods: {
    addCart () {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
      } else {
        this.food.count++
      }
      // 派发一个事件,思考和this.$emit()的区别(先不完成添加商品效果)
    },
    decCart () {
      if (this.food.count) {
        this.food.count--
      }
    }
  },
  computed: {
    foodCount () {
      return this.food.count
    }
  }
}
</script>
<style lang="stylus" scoped>
.cartcontrol
  font-size 0
  display flex
  .cart-dec, .cart-add
    display inline-block
    padding 6px
    line-height 24px
    font-size 24px
    color rgb(0, 160, 220)
  .cart-count
    display inline-block
    vertical-align top
    width 12px
    padding-top 6px
    line-height 24px
    text-align center
    font-size 10px
    color rgb(147, 153, 159)
</style>
